/*
Copyright SecureKey Technologies Inc. All Rights Reserved.

SPDX-License-Identifier: Apache-2.0
*/
package iam

import (
	logApi "git.cloud.inspur.com/ichain/ichain-sdk-go/pkg/core/logging/api"
	"git.cloud.inspur.com/ichain/ichain-sdk-go/pkg/providers/core"
	commtls "git.cloud.inspur.com/ichain/ichain-sdk-go/pkg/util/comm/tls"
)

// Context iam的上下文
type Context interface {
	core.Providers
	Providers
}

// IdentityManagerProvider 身份管理提供者
type IdentityManagerProvider interface {
	IdentityManager(orgName string) (IdentityManager, bool)
}

// IdentityConfig iam的配置接口
type IdentityConfig interface {
	Client() *ClientConfig
	CAConfig(caID string) (*CAConfig, bool)
	CAServerCerts(caID string) ([][]byte, bool)
	CAClientKey(caID string) ([]byte, bool)
	CAClientCert(caID string) ([]byte, bool)
	TLSCACertPool() commtls.CertPool
	CAKeyStorePath() string
	CredentialStorePath() string
}

// ClientConfig iam 客户端配置
type ClientConfig struct {
	Organization    string
	Logging         logApi.LoggingType
	CryptoConfig    CertAndKeyCfg
	TLSKey          []byte
	TLSCert         []byte
	CredentialStore CredentialStoreType
}

// CertAndKeyCfg 密钥和证书的路径
type CertAndKeyCfg struct {
	Path string
}

// CredentialStoreType 证书存储类型
type CredentialStoreType struct {
	Path        string
	CryptoStore struct {
		Path string
	}
}

// EnrollCredential 录入证书对象
type EnrollCredential struct {
	EnrollID     string
	EnrollSecret string
}

// CAConfig ca客户端配置
type CAConfig struct {
	ID               string
	URL              string
	GRPCOptions      map[string]interface{}
	Registrar        EnrollCredential
	CAName           string
	TLSCAServerCerts [][]byte
	TLSCAClientCert  []byte
	TLSCAClientKey   []byte
}

// Providers iam服务的提供者
type Providers interface {
	UserStore() UserStore
	IdentityManagerProvider
	IdentityConfig() IdentityConfig
}
